﻿using System;
using System.Collections.Generic;
using System.Web.UI;
using BLL;
using Model;

public partial class ProductAging_InBoxManu : System.Web.UI.Page
{
    private Aging ag;
    private AgingItem agitem;
    private AgingInfo aginfo;
    private string agingID
    {
        get
        {
            return ViewState["AgingID"].ToString();
        }
        set
        {
            ViewState["AgingID"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            this.DropDownList1.DataSource = DeviceNo.list;
            this.DropDownList1.DataTextField = "StepText";
            this.DropDownList1.DataValueField = "StepValue";
            this.DropDownList1.DataBind();
        }
    }

    public ProductAging_InBoxManu()
    {
        ag = new Aging();
        agitem = new AgingItem();
        aginfo = new AgingInfo();
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
        agingID = this.TextBox1.Text.Trim();
        if (!ag.Aging_ExistsID(agingID))
        {
            string str1 = "此批次编号未生成过，请检查！";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str1 + "');</script>", false);
        }
        else
        {
            BindAging(agingID);
            BindAgingItem(agingID);
        }
    }

    private void BindAging(string agingID)
    {
        aginfo = ag.GetAging_InBox(agingID);
        this.Label2.Text = aginfo.ProductTypeID;
        this.Label3.Text = aginfo.AgingStep;
        this.Label4.Text = aginfo.Department;
        this.Label5.Text = aginfo.Attributes;
        this.Label6.Text = aginfo.TimeSpec.ToString();
        this.Label7.Text = aginfo.TempSpec.ToString();
        this.Label8.Text = aginfo.Amount.ToString();
    }

    private void BindAgingItem(string agingID)
    {
        List<AgingItemInfo> list = (List<AgingItemInfo>)agitem.GetAgingItemsbyID(agingID);
        //foreach (AgingItemInfo aii in list)
        //{
        //    this.ListBox1.Items.Add(aii.ProductSN);
        //}
        this.ListBox1.DataSource = list;
        this.ListBox1.DataTextField = "ProductSN";
        this.ListBox1.DataBind();
        this.Label1.Text = list.Count.ToString();
    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(agingID))
        {
            string str1 = "请先把批次信息查询出来！";
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str1 + "');</script>", false);
        }
        else
        {
            aginfo = ag.GetAging_InBox(agingID);
            if (string.IsNullOrEmpty(aginfo.DeviceName))
            {
                string deviceName = this.DropDownList1.SelectedItem.Text.Trim();
                string userID = User.Identity.Name;
                string str = ag.Aging_InBoxManu(agingID, deviceName, userID);
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
            }
            else
            {
                string str1 = "已经进箱过的批次，无法再次进箱操作!";
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str1 + "');</script>", false);
            }
        }
    }
}
